﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.Practices.EnterpriseLibrary.Data;
using System.Data;

public partial class MRP_DeliveryBill_Update1 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //if (Request.Params["type"] != null)
        //{
        //    string xmlFileName = string.Format(@"XML/MRP_DeliveryBill{0}.xml", Request.Params["type"].ToString());
        //    this.UIServer1.XMLfile = xmlFileName;
        //    UIServer1.DBAllowInsertDetails = false;
        //    UIServer1.DBAllowDelete = false;
        //    UIServer1.DBAllowInsert = false;
        //}Request.Params["type"] != null)

        GridView1.Visible = false;


        if ((Request["ID"] != null))
        {
            string itemID = Request["ID"].ToString();
            if (!string.IsNullOrEmpty(itemID) && (itemID != "0"))
            {

                //if ((Request.Params["EVOL_MODE"] != null) && ((Request.Params["EVOL_ITEMID"] != null)))
                {
                    //string mode = Request.Params["EVOL_MODE"].ToString();
                    //if ((mode.ToLower().Equals("1")) || (mode.ToLower().Equals("110")))
                    {

                        {
                            Database db = DatabaseFactory.CreateDatabase("MRPSqlServer");

                            string sSQL = string.Format("Select T1.BillDO from MRP_ImportExport T1 where T1.ID={0}", itemID);

                            using (IDataReader reader = db.ExecuteReader(CommandType.Text, sSQL))
                            {
                                if (reader.Read())
                                {
                                    if (!string.IsNullOrEmpty(reader[0].ToString()))
                                    {
                                        this.TextBox1.Text = reader[0].ToString();
                                        TextBox1.Enabled = false;
                                        Button1.Visible = false;
                                    }
                                }
                            }

                            sSQL = string.Format("SELECT MRP_MaterialMain.Name as '产品名称', MRP_MaterialMain.MCode as '物料代码', MRP_ImportExport.Quantity as '出库数量', MRP_ImportExport.Quantity as '送货数量',MRP_ImportExport.BillNO as '出库单号' FROM MRP_ImportExport INNER JOIN MRP_MaterialMain ON MRP_ImportExport.MaterialID = MRP_MaterialMain.ID where MRP_ImportExport.BillNO =(Select T1.BillNO from MRP_ImportExport T1 where T1.ID={0})", itemID);
                            DataSet ds = db.ExecuteDataSet(CommandType.Text, sSQL);

                            
                            {
                                GridView1.DataSource = ds.Tables[0].DefaultView;
                                GridView1.DataBind();
                                GridView1.Visible = true;
                            }
                        }

                    }
                }
            }
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (Request["ID"] != null)
        {
            string billDO = string.Empty;

            billDO = TextBox1.Text;
            Database db = DatabaseFactory.CreateDatabase("MRPSqlServer");

            string sSQL = string.Format("Update MRP_ImportExport set billDO='{0}' where BillNO=(Select T2.BillNO from MRP_ImportExport T2 where T2.ID={1})", billDO, Request["ID"].ToString());

            db.ExecuteNonQuery(CommandType.Text, sSQL);

            Response.Redirect("MRP_DeliveryBill.aspx");

        }
    }
}
